<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ page import="co.gov.medellin.sdep.sisdep.domain.UploadFileController" %>
<%String contextRoot = request.getContextPath();%>
<f:loadBundle basename="properties.messages" var="msg" />
<f:view>
<!doctype html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title>SISDEP : Sistema de Informaci<h:outputText value="#{msg.tilde_o}" />n de Espacio P<h:outputText value="#{msg.tilde_u}" />blico</title>
	<meta name="description" content="">
	<meta name="author" content="">
	<link rel="stylesheet" href="<%=contextRoot%>/css/validationEngine.jquery.css" type="text/css">
	<link rel="stylesheet" href="<%=contextRoot%>/css/template.css" type="text/css">
	<link rel="stylesheet" href="<%=contextRoot%>/css/normalize.css">
	<link rel="stylesheet" href="<%=contextRoot%>/css/uniform.css"> <!-- estilos formularios -->
	<link rel="stylesheet" href="<%=contextRoot%>/css/cuerpo.css">
	<link rel="stylesheet" href="<%=contextRoot%>/css/richCustom.css">	
</head>
<body>
<div id="marco"> <!--inicio contenedor --> 
<div class="arriba-cuerpo"></div> 
<div class="cuerpo">
<img src="<%= contextRoot %>/images/logos.png" />
<div class="clear"></div>
<!-- Formulario --> 
<div id="buscador">
<h2>Carga de archivos SISDEP</h2>

<form action="" method="post" enctype="multipart/form-data" name="operatorFileUploadFrm" 
      id="operatorFileUploadFrm" onsubmit="return checkFieldsForm();"  > 
    <script type="text/javascript">
    function checkFieldsForm() {
	    var checkOk = true;
	    var errorMsg = "";
	    // Verifica el archivo seleccionado:
        var fileName = jQ('input[type=file]').val();
	    if(fileName.length > 0) {
	    	checkOk = true;			     
	    } else {
	    	errorMsg += "\n- Debe especificar un archivo para la carga.";
	        checkOk = false;
	    }
		// Verifica la activacion de la capa "Procesando":
	    if(checkOk) {
	    	displayLoadingImage();
	    } else {
		    alert(errorMsg);		        
	        hideLoadingImage();
	    }
        return checkOk;
      }	
	</script>		
	<div class="clear"></div>
	<span class="botones left">
		<label>Archivo a cargar<span class="asterisco"> * </span></label>
		<input type="file" name="attachFile" id="attachFile" size="70" />
	</span>
	<div class="clear"></div>
	<div class="clear"></div>	
	<span class="left" >
	    <label>&nbsp;</label>	
		<input id="fileUploadBtn" name="fileUploadBtn" type="submit" value="CARGAR..." />
	</span>
	<div class="clear"></div>
	(<span class="asterisco"> * </span>) : Campo Obligatorio.
	<div class="clear"></div>
	<span class="botones right">
		<button type="reset" onclick="window.close();">Cerrar</button>
	</span>	
</form>	
</div>
<!-- Fin formulario -->	
    <div class="clear"></div> 
	<div align="left" >
		<strong>Informaci<h:outputText value="#{msg.tilde_o}" />n del Archivo Procesado:</strong>
		<%
			ServletContext context = pageContext.getServletContext();
			
			UploadFileController uploadCtrl = UploadFileController.getInstance();
			String resultMsg = "";
			
			try {
				//uploadCtrl.initUserPortal(request, response);
				resultMsg = uploadCtrl.uploadFileToLocalDirectory(request);
				uploadCtrl.initCurrentFileList();
		%>
				<font color="green"><b><%=resultMsg%></b></font>
				<br/>
		<%
			} catch (Exception e) {
		%>
				<br/><img src="<%= contextRoot %>/images/error_icon.png" />Error:<font color="red">Ha ocurrido un ERROR durante la carga del Archivo.</font>
				uploadCtrl=<%=uploadCtrl %>
				<%=e%>
		<%
			}
		%>         
	</div>	
<!-- Fin formulario --> 
<div class="clear"></div>
<div id="buscador">	
<h:form id="fileCurrentListForm">
     <div class="clear"></div>
		<span class="left"><h2>Archivos anexos actualmente:</h2></span>
	 <div class="clear"></div>             
     <rich:dataTable id="fileCurrentListData" headerClass="standardTable_Header" width="100%"
             border="0" cellpadding="3" cellspacing="1" 
             footerClass="standardTable_Header" rowKeyVar="rowIndex"
             rowClasses="odd,this.style.backgroundColor='#FFFFFF'"
             onRowMouseOver="this.style.backgroundColor='#C0C0C0'"
   			 onRowMouseOut="this.style.backgroundColor='#FFFFFF'"
             var="fileRow" value="#{uploadFileController.fileListModel}"
           	 rows="10" >
      <h:column>
          <f:facet name="header"><h:outputText value="Descargar" /></f:facet>
          <h:outputLink id="downloadFileURL" styleClass="formTextLink" title="Descargar..."				                                   
	                    value="#{facesContext.externalContext.requestContextPath}/uploads/#{fileRow.nombreInterno}" target="_blank" >
	           <h:graphicImage value="/images/edit_icon.png" style="border: 0px solid #FFFFFF;" />
	      </h:outputLink>
      </h:column>
      <h:column>
          <f:facet name="header" ><h:outputText value="Nombre" /></f:facet>
          <h:outputText value="#{fileRow.nombreOriginal}" />
      </h:column>
      <h:column>
          <f:facet name="header" ><h:outputText value="Fuente" /></f:facet>
          <h:outputText value="#{fileRow.tipoFuente}" />
      </h:column>
      <h:column>
          <f:facet name="header" ><h:outputText value="Tipo" /></f:facet>
          <h:outputText value="#{fileRow.mimetype}" />
      </h:column>
   </rich:dataTable>
	
	<h:panelGrid columns="1" styleClass="tablapaginacion" columnClasses="standardTable_ColumnCentered" >
		<rich:datascroller id="currentFileListScroll" for="fileCurrentListData" fastStep="10"
			pageIndexVar="pageIndex" styleClass="scroller" maxPages="8">
			<f:facet name="first_disabled">
			</f:facet>
			<f:facet name="last_disabled">
			</f:facet>
			<f:facet name="previous">
					<h:graphicImage url="/images/arrow-previous.gif" />
			</f:facet>
			<f:facet name="next">
					<h:graphicImage url="/images/arrow-next.gif" />
			</f:facet>
			<f:facet name="fastforward_disabled">
			</f:facet>
			<f:facet name="fastrewind_disabled">
			</f:facet>
		</rich:datascroller>
	</h:panelGrid>
</h:form>
</div>
<!-- Fin tabla -->
</div>
<div class="abajo-cuerpo"></div> <!-- Para ver borde redondo en IE -->
</div> <!-- Fin contenedor -->
<div class="footer"></div>
<script src="<%=contextRoot%>/js/jquery/lib/jquery-1.7.2.min.js"></script>
<script src="<%=contextRoot%>/js/script.js" type="text/javascript"></script>
<%@ include file="../include/validationStatus.jsp" %>
<%@ include file="../include/modalMessageWindow.jsp" %>
</body>
</html>
</f:view>